(function($){
	$.fn.extend({
		comcomcom:function (divId,sql,start,offset,total,func_dwr){
		    var c = sql + " limit " + start + "," + offset;
			func_dwr(c);
			var divObj = document.getElementById(divId);
			
			$(divObj).find("div").remove();
			
			var divcontainer = "<div ></div>";
			$(divObj).append(divcontainer);
			if(typeof $(divObj).find("div select").get(0) ==  "undefined"){
				
				var selectPage  = document.createElement('select');
				for(var i=0;i<Math.ceil(total/offset);i++){
					selectPage.options[i] = new Option(i+1,i);
				}
				$(selectPage).change(function(){
					commonPage(divId,sql,this.options[this.options.selectedIndex].value * offset,offset,total,func_dwr);
				});
				var theSelectedIndex = start/offset;
				selectPage.options[theSelectedIndex].selected = "selected";
				$(divObj).find("div").append(selectPage);
			}else {
			}
			var lastRecordOfCurentPage = (eval(start+1+offset)>total)?total:eval(start+offset);
			var pageSelectObj = $(divObj).find("div select");
			pageSelectObj.before("<a>"+"第"+eval(start+1)+"-"+lastRecordOfCurentPage+"条&nbsp;"+"共"+total+"条&nbsp;"+"第"+eval(start/offset+1)+"页&nbsp;共"+Math.ceil(total/offset)+"页 &nbsp</a>");
			
			
			if(eval(start)==0){
				var aFirst = '<button  disabled="true"  >';
				aFirst += '首页</button>';
				pageSelectObj.before(aFirst);
				 
				pageSelectObj.before("&nbsp;");
				 
				var aPrevious = '<button   disabled="true"  >';
				aPrevious += '上一页</button>';
				pageSelectObj.before(aPrevious);
				
				pageSelectObj.before("&nbsp;");
			}else{
				var aFirst  = document.createElement('button');
				aFirst.innerHTML = '首页';
				$(aFirst).bind("click",function(){
					//alert(0);
					commonPage(divId,sql,0,offset,total,func_dwr);
				});
				pageSelectObj.before($(aFirst));
				
				pageSelectObj.before("&nbsp;");
				
				var checkPrevious = (eval(start-offset)>=0)?eval(start-offset):0;
				aPrevious = document.createElement('button');
				aPrevious.innerHTML = '上一页';
				$(aPrevious).bind("click",function(){
					//alert(-1+"#"+checkPrevious);
					commonPage(divId,sql,checkPrevious,offset,total,func_dwr);
				});
				pageSelectObj.before($(aPrevious));
				
				pageSelectObj.before("&nbsp;");
				

			}
			
			if(eval(start)==eval((Math.ceil(total/offset)-1)*offset)){
				var aNext = '<button  disabled="true" >';
				aNext += '下一页</button>';
				pageSelectObj.before(aNext);
				
				pageSelectObj.before("&nbsp;");
				
				var aLast = '<button  disabled="true" >';
				aLast += '尾页</button>';
				pageSelectObj.before(aLast);
				pageSelectObj.before("&nbsp;");
			}else{
				var checkNext = (eval(start+offset)<=eval((Math.ceil(total/offset)-1)*offset))? eval(start+offset):eval((Math.ceil(total/offset)-1)*offset);
				aNext = document.createElement('button');
				aNext.innerHTML = '下一页';
				$(aNext).bind("click",function(){
					//alert(-1+"#"+checkNext);
					commonPage(divId,sql,checkNext,offset,total,func_dwr);
				});
				pageSelectObj.before($(aNext));
				
				pageSelectObj.before("&nbsp;");
				var aLast = document.createElement('button');
				aLast.innerHTML = '尾页';
				
				$(aLast).bind("click",function(){
					//alert(10000+"#"+eval((Math.ceil(total/offset)-1)*offset));
					commonPage(divId,sql,eval((Math.ceil(total/offset)-1)*offset),offset,total,func_dwr);
				});
				pageSelectObj.before($(aLast));
				
				pageSelectObj.before("&nbsp;");
				
			
			}
		}
	});

})(jQuery);
